//
//  Development_Map_Vm.swift
//  LocaLink
//
//  Created by Icy on 2017/3/25.
//  Copyright © 2017年 Icy. All rights reserved.
//

import RxSwift
import Result
import SwiftyJSON
import NetWorkCore
import ModelProtocol

/*
 owner:cy
 update:2016年08月27日10:14:09
 info: 修改铺货订单状态 的viewmodel
 VC:   有多个
 model: DetailsModel
 */
class Development_Map_Vm {
    
    /*
     接收返回的数据
     */
    /// 是否更新成功
    let developmentList = PublishSubject<[DevelopmentModel]>()
    /*
     通用设置
     */
    /// 表示正在刷新中
    let loading = ActivityIndicator()
    /// 保存错误
    let error = PublishSubject<MikerError>()
    private let disposeBag = DisposeBag()
    
    init(refreshTriger:Observable<(userName: String, token: String)>) {
        refreshTriger
            .map{ HomeApi.GetAllCommunities(userName: $0.userName, token: $0.token)}
            .emeRequestApiForArray(DevelopmentModel.self, activityIndicator: loading)
            .subscribe(onNext: { (result) in
                switch result{
                case .success(let data):
                    self.developmentList.onNext(data)
                case .failure(let error):
                    self.error.onNext(error)
                }
            })
            .disposed(by: disposeBag)
        

    }
    
}
